package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.BaseCategory3;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 专辑分类的mapper映射
 */
@Mapper
public interface BaseCategory3Mapper extends BaseMapper<BaseCategory3> {

    /**
     * 根据一级分类id查询三级分类列表的前7个
     *
     * @param category1Id
     * @return
     */
    @Select("SELECT\n" +
            "  t2.id,\n" +
            "  t2.category2_id,\n" +
            "  t2.NAME,\n" +
            "  t2.order_num,\n" +
            "  t2.is_top\n" +
            "FROM\n" +
            "  base_category2 t1\n" +
            "  INNER JOIN base_category3 t2 ON t1.id = t2.category2_id\n" +
            "WHERE\n" +
            "  t1.category1_id = #{category1Id}\n" +
            "  AND t1.is_deleted = 0\n" +
            "  AND t2.is_deleted = 0\n" +
            "ORDER BY\n" +
            "  t2.is_top\n" +
            "  LIMIT 7")
    List<BaseCategory3> selectTopCategory3(@Param("category1Id") Long category1Id);
}
